package cn.anlaser.service;

import java.util.List;
import java.util.Map;

import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;

import cn.anlaser.entity.BasicEntity;
import cn.anlaser.form.CommonForm;
import cn.anlaser.page.QueryPage;
import cn.anlaser.page.QuerySpecification;
import cn.anlaser.repository.BasicRepository;
import cn.anlaser.utils.SearchFilter;

public interface BasicService<Form extends CommonForm, Repository extends BasicRepository<Entity>, Entity extends BasicEntity> {
	public static final String SUCC = "0";
	public static final String ERROR = "1";

	public abstract Repository getRepository();

	/**
	 * @return
	 */
	public Map<String, SearchFilter> buildFilter();

	/**
	 * @return
	 */
	public Map<String, SearchFilter> buildByForm(Form form);

	/**
	 * @return 模块名称
	 */
	public String module();

	/**
	 * @param id
	 * @return 获取实体
	 */
	public Entity findById(Long id);

	/**
	 * @param entity
	 *            新增实体
	 * @return
	 */
	public Entity add(Form form);

	/**
	 * @param entity
	 *            修改实体
	 */
	public Entity edit(Form form);

	/**
	 * @param entity
	 *            新增实体
	 * @return
	 */
	public Entity add(Entity entity);

	/**
	 * @param entity
	 *            修改实体
	 */
	public Entity edit(Entity entity);

	/**
	 * @return
	 */
	public QueryPage<Entity> findByPage(Pageable pageable);

	public QueryPage<Entity> findAll(final Form form, Pageable pageable);

	public List<Entity> findByForm(final Form form);

	/**
	 * @return
	 */
	public List<Entity> findAll(final Specification<Entity> spec);

	/**
	 * @return
	 */
	public List<Entity> findAll();

	/**
	 * @param id
	 *            删除
	 */
	public void delete(Long id);
	
	public void delete(Entity entitys);

	/**
	 * @param idList
	 */
	public void delete(Iterable<Entity> entitys);

	/**
	 * @param spec
	 * @param pageable
	 * @return
	 */
	public QueryPage<Entity> findAll(QuerySpecification<Entity> spec, Pageable pageable);

}
